﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Windows.Markup;
using System.Data;
using System.ComponentModel;

namespace CrazyWorship1
{
    /// <summary>
    /// Interaction logic for ClientManagerControl.xaml
    /// </summary>
    public partial class ClientManagerControl : UserControl, INotifyPropertyChanged 
    {
        public ClientManagerControl()
        {
            InitializeComponent();
            this.DataContextChanged += new DependencyPropertyChangedEventHandler(ClientManagerControl_DataContextChanged);

            
        }
        void ClientManagerControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {

        }
       
        public void SetClientManager(ClientManager cm)
        {
    
            this.DataContext = this;
       
            _clientManager = cm;
         
        }
        ClientManager _clientManager;
        public ClientManager ClientManager
        {
            get
            {
                return _clientManager;
            }
        }
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            _clientManager.AddClient(textBox1.Text);
        }

        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            _clientManager.RemoveClient((Client)clientListBox.SelectedItem);
        }



        private void screenEnabled_Checked(object sender, RoutedEventArgs e)
        {
           
           // NotifyPropertyChanged("IsVideoEnabled");
        }



        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            { 
                PropertyChanged(this, new PropertyChangedEventArgs(property)); 
            }
        }

        #endregion

        private void clientListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            NotifyPropertyChanged("CheckScreen");
            NotifyPropertyChanged("SelectedScreen");
        }
        public Screen SelectedScreen
        {
            get
            {
                return _clientManager.GetScreen((ScreenInfo)screenListBox.SelectedItem);
            }
            set
            {

            }
        }
        public bool CheckScreen
        {
            get
            {
                return _clientManager.ClientList.ScreenList.HasScreen((ScreenInfo)screenListBox.SelectedItem);
            }
            set
            {
                if (!CheckScreen)
                {
                    _clientManager.AddScreen((ScreenInfo)screenListBox.SelectedItem,new Rectangle(0,0,160,90));
                }
                else
                {
                    _clientManager.RemoveScreen((ScreenInfo)screenListBox.SelectedItem);
                }
                NotifyPropertyChanged("CheckScreen");
                NotifyPropertyChanged("SelectedScreen");
            }
        }
        private void screenListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            NotifyPropertyChanged("CheckScreen");
            NotifyPropertyChanged("SelectedScreen");
        }
    }


    
}
